//
//  WorkingViewController.swift
//  HuaYun
//
//  Created by enghou on 2018/7/9.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

import UIKit


class WorkingViewController: BaseViewController {

    @IBAction func toProjectList(_ sender: Any) {
        let list = ProjectListViewController()
        list.title = "项目列表"
        self.push(destination: list)
    }
    
    @IBOutlet weak var stasticButton: ImageTextButton!
    @IBOutlet weak var comprehensiveButton: ImageTextButton!
    @IBOutlet weak var projectButton: ImageTextButton!
    @IBOutlet weak var purchasingButton: ImageTextButton!
    @IBOutlet weak var saleButton: ImageTextButton!
    @IBOutlet weak var bxButton: ImageTextButton!
    
    @IBOutlet weak var bannerView: ICycleView!
    @IBAction func toWorkTimeAction(_ sender: Any) {
        let work = MyWorkTimeViewController()
        work.title = "工时管理"
        self.push(destination: work)
    }
    
    override func path(for name: String) -> String {
        return PriorityPath
    }
    @IBAction func bxAction(_ sender: Any) {
        let bx = ReimbursementListViewController()
        bx.title = "报销辅助列表"
        self.push(destination: bx)
        
    }
    
    override func param(for name: String) -> Dictionary<String, Any> {
        return ["parentId":"c03f3c0d75ae4649b5086da2676b9092"]
    }
    
    override func method(for name: String) -> NetMethod {
        return .get
    }
    
    @IBOutlet weak var bxbtn: ImageTextButton!
    override func success(for name: String) -> NetSuccess {
        
        func suc(json: JSON)->Void{
            if json.contents?["success"]?.bool == true {
                if let data = json.contents?["data"]?.contents {
                    if let _ = data["APPpurchasing"] {
                        purchasingButton.isEnabled = true
                    } else {
                        purchasingButton.isEnabled = false
                    }
                    if let _ = data["APPoperationAnalysis"] {
                        stasticButton.isEnabled = true
                    } else {
                        stasticButton.isEnabled = false
                    }
                    
                    if let _ = data["APPmarketing"] {
                        saleButton.isEnabled = true
                    } else {
                        saleButton.isEnabled = false
                    }
                    
                    if let _ = data["APPcomperhensivePlan"] {
                        comprehensiveButton.isEnabled = true
                    } else {
                        comprehensiveButton.isEnabled = false
                    }
                    if let _ = data["APPproject"] {
                        projectButton.isEnabled = true
                    } else {
                        projectButton.isEnabled = false
                    }
                    if let _ = data["APPsweepPay"] {
                        User.configScan(ifscan: true)
                    } else {
                        User.configScan(ifscan: false)
                    }
                }
            }
        }
        return suc
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    @IBOutlet weak var stackContainer: UIStackView!
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.automaticallyAdjustsScrollViewInsets = false
        
        bannerView.pageIndicatorTintColor = .gray
        
        bannerView.currentPageIndicatorTintColor = .mainColor
        
        bannerView.pictures = [Bundle.main.path(forResource: "banner1", ofType: "png")!,Bundle.main.path(forResource: "banner2", ofType: "png")!,Bundle.main.path(forResource: "banner3", ofType: "png")!]
        self.load(with: "priority")
        NotificationCenter.default.addObserver(self, selector: #selector(determineentry), name: Notification.Name(rawValue: "UserInfoReady"), object: nil)
    }

    
    
    @objc func determineentry()->Void{
        let canenter = User.canEnter
        if canenter == true {
            stasticButton.isEnabled = true
            comprehensiveButton.isEnabled = true
        } else {
            stasticButton.isEnabled = true
            comprehensiveButton.isEnabled = true
        }
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func projectManageAction(_ sender: Any) {
        
        let projectList = ProjectListViewController()
        
        projectList.title = "项目列表"
        
        self.push(destination: projectList)
    }
    
    @IBAction func purchaseManageAction(_ sender: Any) {
        
        let purchase = PurchaseContactTableViewController()
        
        purchase.title = "采购联系单列表"
        
        self.push(destination: purchase)
        
    }

    @IBAction func salesManageAction(_ sender: Any) {
        
        let vc = VCLoader.vc(with: "SalesManagement", storyboardid: "SalesManagementViewController")
        
        self.push(destination: vc!)
        
    }
    
    
}
